Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfkit

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfkit

A PDF generation library for Node.js

  • 0.8.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
701K
increased by5.54%
Maintainers
1
Weekly downloads
 
Created

What is pdfkit?

PDFKit is a JavaScript library for generating PDF documents, allowing you to create multi-page documents with text, images, vector graphics, and more. It is highly customizable and can be used both in Node.js and browser environments.

What are pdfkit's main functionalities?

Text

This feature allows you to add text to your PDF document. The code sample demonstrates how to create a PDF document and add a 'Hello, World!' text at coordinates (100, 100) with a font size of 25.

const PDFDocument = require('pdfkit');
const fs = require('fs');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

doc.fontSize(25).text('Hello, World!', 100, 100);

doc.end();

Images

This feature allows you to add images to your PDF document. The code sample demonstrates how to add an image to the PDF at coordinates (100, 150) with a width of 300 units.

const PDFDocument = require('pdfkit');
const fs = require('fs');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

doc.image('path/to/image.png', 100, 150, {width: 300});

doc.end();

Vector Graphics

This feature allows you to draw vector graphics such as rectangles, circles, and lines. The code sample demonstrates how to draw a red rectangle at coordinates (100, 100) with a width and height of 200 units.

const PDFDocument = require('pdfkit');
const fs = require('fs');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

doc.rect(100, 100, 200, 200).fill('#FF0000');

doc.end();

Tables

This feature allows you to create tables within your PDF document. The code sample demonstrates how to create a simple table with headers and rows.

const PDFDocument = require('pdfkit');
const fs = require('fs');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

doc.text('Table Example', 100, 50);

doc.moveDown();
const table = {
  headers: ['Header 1', 'Header 2', 'Header 3'],
  rows: [
    ['Row 1 Col 1', 'Row 1 Col 2', 'Row 1 Col 3'],
    ['Row 2 Col 1', 'Row 2 Col 2', 'Row 2 Col 3'],
  ]
};

doc.table(table, {width: 500});

doc.end();

Links

This feature allows you to add hyperlinks to your PDF document. The code sample demonstrates how to add a clickable link that directs to Google's website.

const PDFDocument = require('pdfkit');
const fs = require('fs');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

doc.text('Click here to visit Google', 100, 100).link(100, 100, 160, 27, 'http://www.google.com');

doc.end();

Other packages similar to pdfkit

Keywords

FAQs

Package last updated on 02 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc